home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / basic / ezmouse.exe / MSMOUSE.ASM < prev    next >
Encoding:
Assembly Source File  |  1991-12-25  |  4.1 KB  |  159 lines

  1. ;               MOUSE ROUTINES
  2. ;              Written by FRED SEXTON Jr.
  3. ;               using MASM 6.0
  4. ;           Hereby released to public domain
  5. ;
  6. OPTION EXPR16
  7. .MODEL MEDIUM
  8. hookmouse    PROTO  PASCAL ,mdat:PTR WORD
  9. unhookmouse  PROTO  PASCAL
  10. nu_tyme      PROTO
  11. m_sub1         PROTO
  12. mreset         PROTO  PASCAL ,mok:PTR WORD
  13. mcuron         PROTO  PASCAL
  14. mcuroff      PROTO  PASCAL
  15. msetlim      PROTO  PASCAL ,minx:PTR WORD,maxx:PTR WORD,
  16.                 miny:PTR WORD,maxy:PTR WORD
  17. msetloc      PROTO  PASCAL ,sx:PTR WORD,sy:PTR WORD
  18. .DATA
  19. mdofs      WORD    ?
  20. tick      BYTE    9
  21. oldintad  WORD    2 dup(?)
  22.  
  23. .CODE
  24. nu_tyme PROC uses ds si             ;this is the routine that will
  25.     mov        si,seg tick             ;be called by clock interrupt
  26.     mov        ds,si                ;(18.2 times/second)
  27.     dec        tick                ;interrupt 1CH is called by
  28.     .IF        zero?                ;interrupt 08H
  29.     mov        tick,9
  30.     mov     si,mdofs
  31.     mov     word ptr ds:[si+2],0        ;every .5 sec set click counts
  32.     mov     word ptr ds:[si+6],0        ;to zero
  33.     .ENDIF
  34.     iret
  35. nu_tyme ENDP
  36.  
  37. m_sub1    PROC uses ds                ;this is the routine that will
  38.     mov     si,SEG mdofs            ;be called by mouse activity
  39.     mov     ds,si
  40.     mov     si,mdofs
  41.     mov     ds:[si+8],cx            ;mouse location
  42.     mov     ds:[si+10],dx
  43.     mov     ah,al
  44.     and     al,110y
  45.     .if al == 2                 ;left button press
  46.     mov     word ptr ds:[si],1
  47.     mov     word ptr ds:[si+6],0
  48.     inc     word ptr ds:[si+2]
  49.     mov        tick,9
  50.     .elseif al == 4                ;left button release
  51.     mov     word ptr ds:[si],0
  52.     .endif
  53.     mov     al,ah
  54.     and     al,11000y
  55.     .if al == 8                 ;right button press
  56.     mov     word ptr ds:[si+4],1
  57.     mov     word ptr ds:[si+2],0
  58.     inc     word ptr ds:[si+6]
  59.     mov        tick,9
  60.     .elseif al == 16
  61.     mov     word ptr ds:[si+4],0        ;right button release
  62.     .endif
  63.     ret
  64. m_sub1    endp
  65.  
  66. hookmouse  PROC PASCAL uses ds es, mdat:PTR WORD
  67.     mov     bx,mdat
  68.     mov     mdofs,bx
  69.     mov     ax,SEG m_sub1            ;ES:DX points to user mouse
  70.     mov     es,ax                ;event handler
  71.     mov     dx,OFFSET m_sub1
  72.     mov     ax,000CH
  73.     mov     cx,31                ;set user-defined mouse
  74.     cli                     ;event handler
  75.     int     33H
  76.     sti
  77.     mov        ax,351CH                ;get interrupt 1CH vector
  78.     int        21h
  79.     mov        oldintad,bx             ;save original address
  80.     mov        oldintad+2,es            ;of user timer handler
  81.     mov     dx,OFFSET nu_tyme            ;DS:DX points to new
  82.     mov     ax,SEG nu_tyme            ;user timer handler
  83.     mov     ds,ax
  84.     mov     ax,251CH                ;set interrupt 1CH vector
  85.     cli
  86.     int     21h
  87.     sti
  88.     ret
  89. hookmouse  endp
  90.  
  91. unhookmouse PROC PASCAL uses ds
  92.     mov     dx,oldintad                ;DS:DX points to original
  93.     mov     ax,oldintad+2            ;user timer handler
  94.     mov     ds,ax
  95.     mov     ax, 251CH                ;set interrupt 1CH vector
  96.     cli
  97.     int     21h
  98.     xor        ax,ax                ;reset mouse
  99.     int     33H
  100.     sti
  101.     ret
  102. unhookmouse    ENDP
  103.  
  104. mreset    PROC PASCAL ,mok:PTR WORD
  105.     xor        ax,ax
  106.     int     33H                 ;reset mouse
  107.     mov     bx,mok
  108.     .if     ax==0FFFFH
  109.     mov     word ptr [bx],1            ;mouse driver found
  110.     .else
  111.     mov     word ptr [bx],0            ;mouse driver not found
  112.     .endif
  113.     ret
  114. mreset    endp
  115.  
  116. mcuron    PROC  PASCAL
  117.     mov        ax,1                ;turn on mouse cursor
  118.     int     33H
  119.     ret
  120. mcuron    endp
  121.  
  122. mcuroff    PROC  PASCAL
  123.     mov        ax,2                ;turn off mouse cursor
  124.     int     33H
  125.     ret
  126. mcuroff    endp
  127.  
  128. msetlim PROC  PASCAL ,minx:PTR WORD,maxx:PTR WORD,
  129.               miny:PTR WORD,maxy:PTR WORD
  130.     mov     bx,minx
  131.     mov     cx,[bx]
  132.     mov     bx,maxx
  133.     mov     dx,[bx]
  134.     mov        ax,7                ;set horizontal limit
  135.     int     33H
  136.     mov     bx,miny
  137.     mov     cx,[bx]
  138.     mov     bx,maxy
  139.     mov     dx,[bx]
  140.     mov        ax,8                ;set vertical limit
  141.     int     33H
  142.     ret
  143. msetlim endp
  144.  
  145. msetloc PROC  PASCAL ,sx:PTR WORD,sy:PTR WORD
  146.     mov     si,mdofs
  147.     mov     bx,sx
  148.     mov     cx,[bx]
  149.     mov     ds:[si+8],cx            ;set mx
  150.     mov     bx,sy
  151.     mov     dx,[bx]
  152.     mov     ds:[si+10],dx            ;set my
  153.     mov     ax,4                ;set mouse location
  154.     int     33H
  155.     ret
  156. msetloc endp
  157.  
  158. end
  159.